package com.fadadianqi.logistics.admin.net.mina;

import com.fadadianqi.logistics.admin.net.Packet;
import com.fadadianqi.logistics.admin.net.PacketDeliverException;
import com.fadadianqi.logistics.admin.net.PacketDeliverer;
import com.fadadianqi.logistics.admin.net.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class NIOPacketDeliverer implements PacketDeliverer {

    private static final Log log = LogFactory.getLog(NIOPacketDeliverer.class);

    @Override
    public void deliver(Packet packet) throws PacketDeliverException {
        if (packet == null) {
            throw new PacketDeliverException("Packet is null.");
        }
        Session session = packet.getSession();
        if (session == null) {
            throw new PacketDeliverException("Session is null, packet:" + packet.toString());
        }
        log.info("#deliver#, " + packet.toString());
        session.process(packet);
    }

}
